
#ifndef RTTRANSPORTOPENSSL_H
#define RTTRANSPORTOPENSSL_H

#include "RtTransportTcp.h"
#include "RtMessageBlock.h"
#include <openssl/ssl.h>

class /*RT_API_EXPORT*/ CRtTransportOpenSsl : public CRtTransportTcp
{
public:
	CRtTransportOpenSsl(IRtReactor *pReactor);
	virtual ~CRtTransportOpenSsl();

	int InitSsl(CRtConnectionManager::CType aType);

	// interface IRtEventHandler
	virtual int OnInput(RT_HANDLE aFd = RT_INVALID_HANDLE);

	// interface IRtTransport
	virtual RtResult SendData(CRtMessageBlock &aData, CRtTransportParameter *aPara = NULL);
	virtual RtResult GetOption(DWORD aCommand, LPVOID aArg);
	
	int RecvFromSocket();

	int DoBioRecv(LPSTR aBuf, DWORD aLen, int &aErr);
	int DoBioSend(LPCSTR aBuf, DWORD aLen, int &aErr);

	SSL* GetSslPtr();

	static void TraceOpenSslError(LPCSTR aFuncName, LPVOID pThis);

protected:
	virtual RtResult Close_t(RtResult aReason);

	static int VerifyCallback(int aOk, X509_STORE_CTX *aCtx);

private:
	static SSL_CTX *s_pSslCtx;
	
	SSL *m_pSsl;
	CRtMessageBlock m_mbSslRecvBuffer;
	CRtConnectionManager::CType m_Type;
};

#endif // !RTTRANSPORTOPENSSL_H
